package client.behavioral.responsibility_chain;

import org.junit.Test;
import uml.behavioral.responsibility_chain.*;

import java.util.ArrayList;

/**
 * 职责链--客户端<br>
 * on 2023/1/1 1:51
 */
public class Client {
    @Test
    public void t() {
        Approver d, vp, p, c;
        d = new Director("王南");
        vp = new VicePresident("李北");
        p = new President("蔡西");
        c = new Congress("张东");
        //构建审批职责链: d ==> vp ==> p ==> c
        d.setNextApprover(vp);
        vp.setNextApprover(p);
        p.setNextApprover(c);
        //模拟用户提交的请求
        PurchaseRequest pr1 = new PurchaseRequest(4, "dd313124124189541", "购买1000个鼠标");
        PurchaseRequest pr2 = new PurchaseRequest(5, "dd313124124189542", "购买25台4K触摸显示屏");
        PurchaseRequest pr3 = new PurchaseRequest(10, "dd313124124189543", "购买10台主机");
        PurchaseRequest pr4 = new PurchaseRequest(15, "dd313124124189544", "收购联想");
        PurchaseRequest pr5 = new PurchaseRequest(3000, "dd313124124189545", "收购特斯拉");
        ArrayList<PurchaseRequest> requests = new ArrayList<>();
        requests.add(pr1);
        requests.add(pr2);
        requests.add(pr3);
        requests.add(pr4);
        requests.add(pr5);
        //将请求传递到审批链上，开始处理
        for (PurchaseRequest request : requests) {
            d.dealWith(request);
        }
    }
}
